var coreExam = Gikam.getPageObject({

    baseUrl : IFM_CONTEXT + '/secure/baseline/rm/train/exams',

    getEditListColumns : function() {
        return [ {
            checkbox : true,
        }, {index: true},{
            field : 'examName',
            title : 'T_CORE_EXAM.EXAMNAME',
            type : 'link'
        }, /*{
            field : 'questionMethod',
            title : 'T_CORE_EXAM.QUESTIONMETHOD',
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'questionMethod'
            },
        },*/ {
            field : 'ext$.tmplname',
            title : 'T_CORE_EXAM_TMPL.TMPLNAME'
        }, {
            field : 'ext$.totalscore',
            title : 'T_CORE_EXAM_TMPL.TOTALSCORE'
        }, /*{
            field : 'examBeginTime',
            title : 'T_CORE_EXAM.EXAMBEGINTIME'
        }, {
            field : 'examEndTime',
            title : 'T_CORE_EXAM.EXAMENDTIME'
        }, {
            field : 'examDuration',
            title : 'T_CORE_EXAM.EXAMDURATION'
        },*/ /*{
            field : 'examCategory',
            title : 'T_CORE_EXAM.EXAMCATEGORY',
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'coreQuestionCategory'
            },
        },*/ {
            field : 'lastUpdatedByName',
            title : 'T_CORE_EXAM.LASTUPDATEDBYNAME'
        }, {
            field : 'lastUpdatedTime',
            title : 'T_CORE_EXAM.LASTUPDATEDTIME'
        } ];
    },
    
    getChooseListColumns : function() {
        return [ {index: true},{
            field : 'examName',
            title : 'T_CORE_EXAM.EXAMNAME'
        }, /*{
            field : 'questionMethod',
            title : 'T_CORE_EXAM.QUESTIONMETHOD',
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'questionMethod'
            },
        },*/ {
            field : 'ext$.tmplname',
            title : 'T_CORE_EXAM_TMPL.TMPLNAME'
        }, {
            field : 'ext$.totalscore',
            title : 'T_CORE_EXAM_TMPL.TOTALSCORE'
        }, /*{
            field : 'examBeginTime',
            title : 'T_CORE_EXAM.EXAMBEGINTIME'
        }, {
            field : 'examEndTime',
            title : 'T_CORE_EXAM.EXAMENDTIME'
        }, {
            field : 'examDuration',
            title : 'T_CORE_EXAM.EXAMDURATION'
        },*/ /*{
            field : 'examCategory',
            title : 'T_CORE_EXAM.EXAMCATEGORY',
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'coreQuestionCategory'
            },
        },*/ {
            field : 'lastUpdatedByName',
            title : 'T_CORE_EXAM.LASTUPDATEDBYNAME'
        }, {
            field : 'lastUpdatedTime',
            title : 'T_CORE_EXAM.LASTUPDATEDTIME'
        } ];
    },

    getBaseInfoFormFields : function() {
        return [ {
            field : 'examName',
            title : 'T_CORE_EXAM.EXAMNAME',
            preInsert : true,
            validators : [ 'notEmpty','strLength(0,90]' ]
        }, /*{
            field : 'questionMethod',
            title : 'T_CORE_EXAM.QUESTIONMETHOD',
            type : 'select',
            category : 'sys',
            firstBlank : false,
            param : {
                codeCategoryId : 'questionMethod'
            },
            preInsert : true,
            validators : [ 'notEmpty' ],
            onChange : function(field, value, index) {
                if (value == 'random') {
                    var questionData = Gikam.getComp('core-exam-detail-question-list-grid').getData();
                    if (Gikam.isEmpty(questionData)) {
                        Gikam.getComp('core-exam-detail-question-tab').hide();
                        return;
                    }
                    
                    var url = coreExam.baseUrl + '/questions';
                    
                    workspace.window.showMask(true);
                    Gikam.del(url, Gikam.getJsonWrapper(null, [ '', questionData ])).done(function(r) {
                        Gikam.getComp('core-exam-detail-question-tab').hide();
                    }).always(function() {
                        workspace.window.closeMask();
                    });
                } else if (value == 'manual') {
                    Gikam.getComp('core-exam-detail-question-tab').show();
                }
            }
        },*/ {
            field : 'ext$.tmplname',
            title : 'T_CORE_EXAM_TMPL.TMPLNAME',
            type : 'choose',
            category : 'exam-tmpl',
            preInsert : true,
            single : true,
            editable : false,
            onAfterChoose : function(rows, i) {
                if (rows) {
                    this.setData({
                        examTmplId : rows[0].id,
                        tmplSingleChoiceQty : rows[0].singleChoiceQty,
                        tmplMultipleChoiceQty : rows[0].multipleChoiceQty,
                        tmplJudgementQty : rows[0].judgementQty,
                        tmplShortAnswerQty : rows[0].shortAnswerQty,
                        tmplCompletionQty : rows[0].completionQty,
                        ext$ : {
                            tmplname : rows[0].tmplName,
                            totalscore : rows[0].totalScore
                        }
                    });
                }
            },
            onClean : function() {
                this.setData({
                    examTmplId : null,
                    tmplSingleChoiceQty : 0,
                    tmplMultipleChoiceQty : 0,
                    tmplJudgementQty : 0,
                    tmplShortAnswerQty : 0,
                    tmplCompletionQty : 0,
                    ext$ : {
                        tmplname : null,
                        totalscore : 0
                    }
                });
            },
            validators : [ 'notEmpty' ]
        }, {
            field : 'ext$.totalscore',
            title : 'T_CORE_EXAM_TMPL.TOTALSCORE',
            readonly : true
        }, /*{
            field : 'examBeginTime',
            title : 'T_CORE_EXAM.EXAMBEGINTIME',
            type : 'dateTime',
            validators : [ 'notEmpty' ],
            onChange : function (field,value,index) {
                if (Gikam.isNotEmpty(this.options.data.examEndTime) && value){
                    let endDate = new Date(this.options.data.examEndTime);
                    let startDate = new Date(value);
                    if(startDate > endDate){
                        this.setData({
                            examBeginTime :'',
                            examDuration : '',
                            id : this.options.data.id
                        });
                        Gikam.alert('STARTDATE.NO.MORE.THAN.ENDDATE');
                    }else{
                        let ss = endDate.getTime() - startDate.getTime();
                        let min = Math.floor(ss/60000);
                        this.setData({
                            examBeginTime : value,
                            examDuration : min,
                            id : this.options.data.id
                        });
                        this.setData({
                            examBeginTime : value,
                            id : this.options.data.id
                        });
                    }
                }
            }
        }, {
            field : 'examEndTime',
            title : 'T_CORE_EXAM.EXAMENDTIME',
            type : 'dateTime',
            validators : [ 'notEmpty' ],
            onChange : function (field,value,index) {
                if (Gikam.isNotEmpty(this.options.data.examBeginTime) && value){
                    let startDate = new Date(this.options.data.examBeginTime);
                    let endDate = new Date(value);
                    if(startDate > endDate){
                        this.setData({
                            examEndTime :'',
                            examDuration : '',
                            id : this.options.data.id
                        });
                        Gikam.alert('STARTDATE.NO.MORE.THAN.ENDDATE');
                    }else{
                        let ss = endDate.getTime() - startDate.getTime();
                        let min = Math.floor(ss/60000);
                        this.setData({
                            examEndTime : value,
                            examDuration : min,
                            id : this.options.data.id
                        });
                    }
                }
            }
        },*/ /*{
            field : 'examDuration',
            title : 'T_CORE_EXAM.EXAMDURATION',
            validators : [ 'integer', 'strLength(0,3]']
        },*/ {

        }, /*{
            field : 'examCategory',
            title : 'T_CORE_EXAM.EXAMCATEGORY',
            type : 'select',
            category : 'sys',
            firstBlank : false,
            param : {
                codeCategoryId : 'coreQuestionCategory'
            },
            validators : [ 'notEmpty' ]
        }*/ ];
    },
    
    getQuestionEditInfoFormFields : function() {
        return [ {
            field : 'ext$.singlechoiceqtyrate',
            title : 'CORE.MODULE.TRAIN.EXAM_QUESTION.FIELD.TITLE.SINGLECHOICEQTY',
            readonly : true,
        },{
            field : 'ext$.multiplechoiceqtyrate',
            title : 'CORE.MODULE.TRAIN.EXAM_QUESTION.FIELD.TITLE.MULTIPLECHOICEQTY',
            readonly : true,
        },{
            field : 'ext$.completionqtyrate',
            title : 'CORE.MODULE.TRAIN.EXAM_QUESTION.FIELD.TITLE.COMPLETIONQTY',
            readonly : true,
        },{
            field : 'ext$.judgementqtyrate',
            title : 'CORE.MODULE.TRAIN.EXAM_QUESTION.FIELD.TITLE.JUDGEMENTQTY',
            readonly : true,
        },{
            field : 'ext$.shortanswerqtyrate',
            title : 'CORE.MODULE.TRAIN.EXAM_QUESTION.FIELD.TITLE.SHORTANSWERQTY',
            readonly : true,
        } ];
    },

    getQuestionColumns : function() {
        return [ {
            checkbox : true
        }, {
            index : true
        }, {
            field : 'ext$.questioncategory',
            title : 'T_CORE_QUESTION.QUESTIONCATEGORY',
            type : 'select',
            width : 100,
            category : 'sys',
            param : {
                codeCategoryId : 'coreQuestionCategory',
                codeClassId : 'biz'
            }
        }, {
            field : 'ext$.questiontype',
            title : 'T_CORE_QUESTION.QUESTIONTYPE',
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'coreQuestionType'
            }
        }, {
            field : 'ext$.questioncontent',
            title : 'T_CORE_QUESTION.QUESTIONCONTENT'
        } ];
    },
    
    getQuestionBankColumns : function() {
        return [ {
            checkbox : true
        }, {
            index : true
        },{
            field : 'questionCategory',
            title : 'T_CORE_QUESTION.QUESTIONCATEGORY',
            type : 'select',
            width : 100,
            category : 'sys',
            param : {
                codeCategoryId : 'coreQuestionCategory',
                codeClassId : 'biz'
            }
        }, {
            field : 'questionType',
            title : 'T_CORE_QUESTION.QUESTIONTYPE',
            type : 'select',
            category : 'sys',
            param : {
                codeCategoryId : 'coreQuestionType'
            }
        }, {
            field : 'questionContent',
            title : 'T_CORE_QUESTION.QUESTIONCONTENT'
        } ];
    }
});